<?php
// +----------------------------------------------------------------------
// | 车钉钉 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.twothink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: YagamiZN
// +----------------------------------------------------------------------

namespace app\admin\controller;
use think\Controller;

/**
 * 后台登陆控制器
 */
class Login extends Controller{
    
    
    //管理登陆
    public function login(){
        return $this->fetch();
    }
    //用户登陆认证
    public function loginCheck(){
        $name=input('param.name');
        $pwd=input('param.pwd');
        $save=input('param.save');
        $user=model('Admin');
        $userinfoObj=$user->where('aname',$name)->find();
        if(empty($userinfoObj)){
            return ['code'=>300,'msg'=>'管理员不存在'];
        }else{
            $userinfo=$userinfoObj->getData();
            $md5Pwd=md5($pwd.$userinfo['pwdkey']);
            if($md5Pwd===$userinfo['apwd']){
                if($save){
                    cookie('aname', $userinfo['aname'], 3600*24*30);
                    cookie('apwd', $userinfo['apwd'], 3600*24*30);
                }
                session('aid', $userinfo['id']);
                session('aname', $userinfo['aname']);
                $user->update('',['id'=>$userinfo['id']]);
                return ['code'=>200,'msg'=>'登陆成功'];
            }else{
                return ['code'=>300,'msg'=>'密码错误'];
            }
        }
    }
    //退出
    public function loginOut(){
        session(null);
        cookie(null);
        $this->redirect('Login/login');
    }
    
    /* 空操作，用于输出404页面 */
    public function _empty(){
        $this->redirect('Index/index');
    }
}
